import dayjs from "dayjs";
import { splitProps } from "solid-js";
import { TableColumn, TableColumnProps } from "solid-table-context";
import { is_null_or_undefined } from "~/utils/object";

export const DateTimeColumn = <T = any,>(
  props: Omit<TableColumnProps<T>, "children"> & { format?: string }
) => {
  const [_, rest] = splitProps(props, ["name", "format"]);

  return (
    <TableColumn {...rest}>
      {(data) =>
        is_null_or_undefined(data[props.name])
          ? ""
          : dayjs(data[props.name] as any).format(
              props.format ?? "YYYY年MM月DD日 HH时mm分"
            )
      }
    </TableColumn>
  );
};
